Imports System.Web.Security
Imports MIMS.WRS.Business
Imports MIMS.WRS.Data
Imports MIMS.WRS.Entities


Public Class ChangePassword1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblErr As System.Web.UI.WebControls.Label
    Protected WithEvents txtUsername As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnOK As System.Web.UI.WebControls.Button
    Protected WithEvents btnCancel As System.Web.UI.WebControls.Button
    Protected WithEvents rowLogin As System.Web.UI.HtmlControls.HtmlTableRow
    Protected WithEvents lblEmail As System.Web.UI.WebControls.Label
    Protected WithEvents linkSignInOther As System.Web.UI.WebControls.LinkButton
    Protected WithEvents txtNewPassword As System.Web.UI.WebControls.TextBox
    Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents Requiredfieldvalidator2 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents CustomValidator3 As System.Web.UI.WebControls.CustomValidator
    Protected WithEvents Requiredfieldvalidator3 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents Customvalidator1 As System.Web.UI.WebControls.CustomValidator
    Protected WithEvents txtConfirmNewPwd As System.Web.UI.WebControls.TextBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If (Not IsPostBack) Then
        
        End If
        btnOK.Attributes.Add("onclick", "javascript:return ValidatePassword();")
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Try
            ShoppingConext.ShopingUserId = ShoppingListService.Login(txtUsername.Text.Trim(), Utilities.HashPassword(txtPassword.Text))
            If (ShoppingConext.ShopingUserId <> 0) Then
                ShoppingConext.ShopingUserEmail = txtUsername.Text.Trim()
                Dim curShoppingUser As New ShoppingUser
                curShoppingUser.UserId = ShoppingConext.ShopingUserId
                curShoppingUser.Email = txtUsername.Text.Trim()
                curShoppingUser.Password = Utilities.HashPassword(txtNewPassword.Text)

                ShoppingListService.UpdateShoppingUser(curShoppingUser)
                Dim strScript As String = "<script language='javascript'>windowClose();</script>"
                Page.RegisterStartupScript("windowClose", "<script language='javascript'>windowClose();</script>")
            Else
                lblErr.Text = "Invalid email or password"
            End If
        Catch ex As Exception
            lblErr.Text = ex.Message
        End Try
    End Sub

    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
        btnCancel.Attributes.Add("onclick", "javascript:window.close();return false;")
    End Sub


End Class
